home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / timeline / stop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  9.3 KB  |  224 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/TimeLine/RCS/stop.c,v 1.11 92/10/01 14:53:28 drapeau Exp Locker: drapeau $ */
  25. /* $Log:    stop.c,v $
  26.  * Revision 1.11  92/10/01  14:53:28  drapeau
  27.  * One minor logic fix, in the PauseResume() function.  Before sending a
  28.  * PauseSelection() message, TimeLine needs to assure that messaging is
  29.  * synchronous so that it can be aware of which applications were able to
  30.  * pause their current selections.  So before sending the PauseSelection
  31.  * message, TimeLine now sets synchronous messaging to "On".
  32.  * In addition, a number of minor cosmetic changes were made, and some slight
  33.  * rearrangement of if-then tests was made to clean up the code and improve
  34.  * readability.
  35.  * 
  36.  * Revision 1.10  92/09/24  17:29:03  drapeau
  37.  * Minor code changes were made to support documents with synchronization
  38.  * information.  When documents with "sync hints" are performed, TimeLine
  39.  * uses asynchronous messaging.  However, when stopping performance of a
  40.  * document, synchronous messaging must be used or TimeLine will "believe" that
  41.  * an error occurred in sending Halt messages (the error is a side effect of the
  42.  * way asynchronous messaging is done in Sun RPC).  To solution is to enable
  43.  * synchronous messaging before sending Halt messages.  This is correct from
  44.  * an interface standpoint as well, since the author will want to be sure that
  45.  * all the components of a document have actually stopped when they were sent
  46.  * Halt messages; asynchronous messaging will not guarantee this.
  47.  * 
  48.  * A number of cosmetic changes were made to improve readability and ANSI
  49.  * compliance.
  50.  * 
  51.  * Revision 1.0  91/09/30  17:03:01  chua
  52.  * Update to version 1.0
  53.  * 
  54.  * Revision 0.46  91/09/26  18:05:50  chua
  55.  * In Stop and PauseResume, before sending any network messages, check that the
  56.  * application is still open by calling CheckAppOpen.
  57.  * 
  58.  * Revision 0.45  91/09/25  13:51:20  chua
  59.  * Changed the instrument field, instInfo, to editInfo.
  60.  * Changed InstrumentInfo to EditInfo.
  61.  * 
  62.  * Revision 0.44  91/09/23  17:20:48  chua
  63.  * Changed StopHandler to Stop and PauseResumeHandler to PauseResume, as these
  64.  * are now notify functions for buttons instead of menu items.
  65.  * 
  66.  * In PauseResume, do not call PlayStop anymore.  The timer still runs when
  67.  * in pause mode.
  68.  * 
  69.  * Revision 0.43  91/09/19  17:29:09  chua
  70.  * Make sure that variables are initialized properly.  Change formatting slightly,
  71.  * so that (if, for, while) statements with only one statement in them will not have
  72.  * braces.
  73.  * 
  74.  * Revision 0.42  91/08/20  16:21:15  chua
  75.  * In the StopHandler and PauseResumeHandler, send a Halt or Pause message to an application
  76.  * only if it is currently in the middle of performing a note.
  77.  * 
  78.  * Revision 0.41  91/08/16  17:07:50  chua
  79.  * 
  80.  * 
  81.  * Revision 0.40  91/08/16  13:49:37  chua
  82.  * Contains the StopHandler and PauseResumeHandler routines.
  83.  *  */
  84.  
  85. static char stoprcsid[] = "$Header: /Source/Media/collab/TimeLine/RCS/stop.c,v 1.11 92/10/01 14:53:28 drapeau Exp Locker: drapeau $";
  86.  
  87. #include "main.h"
  88.  
  89. /*
  90.  * Notify callback function for `stopButton'.  This function will
  91.  * send the SenderHaltSelection message to the applications.  The Halt
  92.  * message is sent to only those applications which are currently in the
  93.  * middle of performing a note.  The PlayStop routine is then called.
  94.  */
  95. void Stop(Panel_item    item,
  96.       Event*    event)
  97. {
  98.   int                i, done;
  99.   int                result;
  100.   TimeLineFramePtr        tlFrame;
  101.   TimeLine_window_objects*    ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  102.   Instrument*            instrument;
  103.   
  104.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  105.   instrument = (Instrument *) FindInstrument(startApp, tlFrame);
  106.   for (i=0; i < numApps; i++, instrument = instrument->next) 
  107.   {
  108.     if (xv_get(instrument->editInfo->MuteChoice,            /* If this instrument should not or cannot be played, then... */
  109.            PANEL_VALUE) != 0 ||                    /* ...go on to the next instrument. */
  110.     CheckAppOpen(tlFrame, instrument, 2) != OK)
  111.       continue;
  112.     done = 0;                                /* Either go through the whole instrument list or a... */
  113.     instrument->currentNote = instrument->firstNote;            /* ...subset of it, depending on the startApp &... */
  114.     while (instrument->currentNote != NULL && !done)            /* ...numApps values */
  115.     {
  116.       if (instrument->currentNote->start  < tlFrame->lastX &&        /* Keep searching while the whole note is before.... */
  117.       instrument->currentNote->end < tlFrame->lastX)        /* ...the virtual clock */
  118.     instrument->currentNote = instrument->currentNote->next;
  119.       else 
  120.     done = 1;
  121.     }
  122.     if (instrument->currentNote != NULL)        
  123.     {
  124.       if (instrument->currentNote->start <= tlFrame->lastX) 
  125.       {
  126.     SenderSynchronousMessaging(instrument->sender, On);        /* Assure that TimeLine blocks until HaltSelection completes */
  127.     result = SenderHaltSelection(instrument->sender);
  128.     if (result == -1) 
  129.     {
  130.       AlertMessage(tlFrame, "Error in sending a halt message.", 
  131.                "Check if the application is still running.", NULL);
  132.       return;
  133.     }
  134.       }
  135.     }
  136.   }                                    /* end for */
  137.   PlayStop();
  138.   return;
  139. }                                    /* end function Stop */
  140.  
  141.  
  142.  
  143. /*
  144.  * Notify callback function for `pauseButton'.
  145.  * If the TimeLine is in pause mode, PlayStop will be called, and a Pause
  146.  * message sent to the applications.  The Pause message is sent to only
  147.  * those applications which are currently in the middle of performing a
  148.  * note.  If the TimeLine is resume mode, a check is made to see what
  149.  * state the TimeLine was in when Pause was called, meaning whether it
  150.  * was doing a PlaySelected or Play/PlayFrom.  The appropriate Play
  151.  * routine will then be called to resume play.
  152.  */
  153.  
  154. void PauseResume(Panel_item    item,
  155.          Event        *event)
  156. {
  157.   Instrument*            instrument;
  158.   int                i, done;
  159.   int                result;
  160.   TimeLineFramePtr        tlFrame;
  161.   TimeLine_window_objects*    ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  162.   
  163.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  164.   if ((tlFrame->status != PauseMode) &&
  165.       (tlFrame->status != PauseSelectedMode))
  166.   {
  167.     xv_set(tlFrame->TimeLine_window->pauseButton,
  168.        PANEL_ITEM_COLOR, gcm_color_index("green"), NULL);
  169.     instrument = (Instrument *) FindInstrument(startApp, tlFrame);
  170.     for (i=0; i < numApps; i++)                        /* Either go through the whole instrument list or a... */
  171.     {                                    /* ...subset of it, depending on startApp & numApps values*/
  172.       if (xv_get(instrument->editInfo->MuteChoice,            /* If this instrument should not or cannot be played, then... */
  173.          PANEL_VALUE) != 0 ||                    /* ...go on to the next instrument. */
  174.       CheckAppOpen(tlFrame, instrument, 2) != OK)
  175.     continue;
  176.       done = 0;
  177.       instrument->currentNote = instrument->firstNote;
  178.       while (instrument->currentNote != NULL && !done)
  179.       {
  180.     if (instrument->currentNote->start  < tlFrame->lastX &&
  181.         instrument->currentNote->end < tlFrame->lastX)        /* Keep searching while whole note is before virtual clock. */
  182.       instrument->currentNote = instrument->currentNote->next;
  183.     else 
  184.       done = 1;
  185.       }
  186.       if (instrument->currentNote != NULL)        
  187.     if (instrument->currentNote->start <= tlFrame->lastX) 
  188.     {
  189.       SenderSynchronousMessaging(instrument->sender, On);        /* Assure that TimeLine blocks until PauseSelection completes */
  190.       result = SenderPauseSelection(instrument->sender);
  191.       if (result == -1) 
  192.       {
  193.         AlertMessage(tlFrame, "Error in sending a pause message.", 
  194.              "Check if the application is still running.", NULL);
  195.         return;
  196.       }
  197.       instrument->playNote = 1;                    /* Remind TimerNotify that this instrument has a note to... */
  198.     }                                /* ...be played */
  199.       instrument = instrument->next;
  200.     }                                    /* end for */
  201.     if (tlFrame->status == PlaySelectedMode ||                /* Set the correct status */
  202.     tlFrame->status == ResumeSelectedMode)
  203.       tlFrame->status = PauseSelectedMode;
  204.     else 
  205.       tlFrame->status = PauseMode;
  206.   }
  207.   else                                    /* Resume is to be done */
  208.   {
  209.     xv_set(tlFrame->TimeLine_window->pauseButton,
  210.        PANEL_ITEM_COLOR, gcm_color_index("black"), NULL);
  211.     if (tlFrame->status == PauseSelectedMode)
  212.     {
  213.       tlFrame->status = ResumeSelectedMode;
  214.       PlaySelectedHandler(item, MENU_NOTIFY);
  215.     }
  216.     else 
  217.     {
  218.       tlFrame->status = ResumeMode;
  219.       PlayFromHandler(item, MENU_NOTIFY);
  220.     }
  221.   }
  222. }                                    /* end function PauseResume */
  223.  
  224.